package com.example.mybatis.controller;

import com.example.mybatis.bean.Catalogue;
import com.example.mybatis.service.CatalogueService;
import com.example.mybatis.utils.ResultUtil;
import com.example.mybatis.utils.validator.DataValidator;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("catalogue")
public class CatalogueController {
    @Resource
    private CatalogueService catalogueService;

    @RequestMapping("selectList")

    public ResultUtil selectList(String name) {
        return catalogueService.selectList(name);

    }

    @RequestMapping("insert")

    public ResultUtil insert(Catalogue catalogue) {
        DataValidator.validator(catalogue);
        return catalogueService.insert(catalogue);


    }

    @RequestMapping("getById")
    public ResultUtil getById(Integer id) {

        return catalogueService.getById(id);


    }

    @RequestMapping("update")

    public ResultUtil update(Catalogue catalogue){

        return catalogueService.update(catalogue);
    }

    @RequestMapping("deleteById")
    public ResultUtil removeById(@RequestBody List<Integer> idList){

        return catalogueService.removeById(idList);
    }
}
